<?php
namespace app\common\controller;

/**
 * 工作记录日记账类
 * Created by PhpStorm.
 * User: tyll
 * Date: 2019/11/26
 * Time: 14:22
 */
class WorkRecordAccount{

    /**
     * 获取日记账统计
     * @param $department
     * @param $start_time
     * @param $end_time
     * @return mixed
     */
    public function get_total($department,$start_time,$end_time){
        $wra_maps = [];
        $wra_maps[] = ['department','=',$department];
        if(!empty($start_time) && !empty($end_time)){
            $start_date = date('Y-m-d',strtotime($start_time));
            $end_date = date('Y-m-d',strtotime($end_time));
            $wra_maps[] = ['now_date','between',[$start_date,$end_date]];
        }

        $list = model('work_record_account')->get_list($wra_maps);

        $income_money = 0;
        $expend_money = 0;
        foreach($list as $k => $v){
            if($v['income_and_expend'] == 1){
                $income_money += $v['money'];
            }elseif($v['income_and_expend'] == 2){
                $expend_money += $v['money'];
            }
        }

        $data['income_money'] = deal_number_div_100($income_money);
        $data['expend_money'] = deal_number_div_100($expend_money);
        return $data;
    }
}